package br.com.sigmah.controller.mbeans;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import org.apache.log4j.Logger;
import org.primefaces.event.FlowEvent;
import br.com.sigmah.controller.facade.ProfessorFacade;
import br.com.sigmah.controller.facade.UtilsFacade;
import br.com.sigmah.controller.utils.ProfessorVO;
import br.com.sigmah.domain.entity.Professor;

@ManagedBean
@RequestScoped
public class ProfessorController{

    private static Logger logger = Logger.getLogger(ProfessorController.class.getName());  

	public ProfessorController(){
		
	}
	
	@ManagedProperty("#{utilsFacade}")
	private UtilsFacade utilsFacade;
	
	@ManagedProperty("#{cursoFacade}")
	private ProfessorFacade professorFacade;
	
	private Professor professor;
	
	private List<Professor> listaProfessor;
	
	private Professor professorSelecionado;
	
	private ProfessorVO professorVO;
	
	@PostConstruct
	public void init(){
		this.professor = new Professor();
		this.professorVO = new ProfessorVO();
		//this.listaProfessor = cursoFacade.buscar(curso);
	}
	

	public void salvar(){
		if(professor != null){
			professorFacade.salvar(professor);
		}
	}
	
	public void buscar(){
		System.out.println("Buscando");
		if(professorVO.getNome()!=null){
			listaProfessor =professorFacade.buscarPorParametros(professorVO);
		}
	
	}
	
	public void excluir(){
		if(professorSelecionado != null){
			professorFacade.excluir(professorSelecionado);
		}
	}
	
	public void atualizar(){
		if(professorSelecionado != null){
			professorFacade.salvar(professorSelecionado);
		}
	}
	
	public void onProcess(){
		System.out.println(professorSelecionado.getNome());

	}
	
	public String onFlowProcess(FlowEvent event) {  
        logger.info("Current wizard step:" + event.getOldStep());  
        logger.info("Next step:" + event.getNewStep());  
      
        return event.getNewStep();  
  
    }


	public UtilsFacade getUtilsFacade() {
		return utilsFacade;
	}


	public void setUtilsFacade(UtilsFacade utilsFacade) {
		this.utilsFacade = utilsFacade;
	}


	public ProfessorFacade getProfessorFacade() {
		return professorFacade;
	}


	public void setProfessorFacade(ProfessorFacade professorFacade) {
		this.professorFacade = professorFacade;
	}


	public Professor getProfessor() {
		return professor;
	}


	public void setProfessor(Professor professor) {
		this.professor = professor;
	}


	public List<Professor> getListaProfessor() {
		return listaProfessor;
	}


	public void setListaProfessor(List<Professor> listaProfessor) {
		this.listaProfessor = listaProfessor;
	}


	public Professor getProfessorSelecionado() {
		return professorSelecionado;
	}


	public void setProfessorSelecionado(Professor professorSelecionado) {
		this.professorSelecionado = professorSelecionado;
	}


	public ProfessorVO getProfessorVO() {
		return professorVO;
	}


	public void setProfessorVO(ProfessorVO professorVO) {
		this.professorVO = professorVO;
	}  
	
	

}
